#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
#TODO: documentation!
"""

__version__ = '$Id: entity.py 191 2008-02-14 05:43:52Z DLacewell $'

from math import pi, sin, cos
from random import randint, random

from pyglet.gl import glPushMatrix, glPopMatrix, glColor3f, glBegin, glEnd, glVertex3f, glTranslatef, GL_POLYGON
from bipy.components import Dynamic, get

class Entity(Dynamic):

    def __init__(self):
        super(Entity, self).__init__()
        x = randint(1,600) - 300
        y = randint(1,400) - 200
        
        pos_comp = get('position')
        if pos_comp:
            self.add_component( pos_comp(x=x, y=y) )
        
        self.dt = random() * pi
        self.r = randint(1,30)

    def draw(self):
        # TODO: draw all entities that are visible to the camera
        x, y, z = self.position.get_pos()
        self.dt += random() * 0.5
        dt = self.dt
        nx = x + self.r * sin(dt)
        ny = y + self.r * cos(dt)
        glPushMatrix()
        glTranslatef(nx, ny, 1.0)
        glColor3f(1.0, 1.0, 1.0)
        glBegin(GL_POLYGON)
        glColor3f(1.0, 0.0, 0.0)
        glVertex3f(0.0, 0.0, 0.0)
        glColor3f(0.0, 1.0, 0.0)
        glVertex3f(75.0, 25.0, 0.0)
        glColor3f(0.0, 0.0, 1.0)
        glVertex3f(25.0, 75.0, 0.0)
        glEnd()
        glPopMatrix()
        pass
        
